package action.login;
import org.apache.struts2.ServletActionContext;

import model.MUser;

import action.common.MyBaseAction;

import com.opensymphony.xwork2.ModelDriven;

import service.interf.IUser;
public class LoginAction extends MyBaseAction<MUser> implements ModelDriven<MUser>{
	
	private static final long serialVersionUID = 4160630049797676394L;
	
	/********************property*****************************************/
	private IUser userService;
	
	/**************************constructor*******************************/
	public LoginAction() {
		super(MUser.class);
	}
	
	/**********************setter and getter*****************************/
	public MUser getModel(){
		return model;
	}
	public IUser getUserService() {
		return userService;
	}
	public void setUserService(IUser userService) {
		this.userService = userService;
	}
	
	/************************* action method *****************************/
	public void login() {
		String r;
		try {
			r = userService.login(model);
		} catch (Exception e) {
			r = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient(ServletActionContext.getResponse(), r);
	}
	
	public void getUser() {
		String r;
		try {
			r = userService.getUser(model);
		} catch (Exception e) {
			r = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient1(ServletActionContext.getResponse(), r);
	}
	
	public void getAllUser() {
		String r;
		try {
			r = userService.getAllUser();
		} catch (Exception e) {
			r = errorHandle.handleErr(e);
		}
		servletHandle.writeToClient1(ServletActionContext.getResponse(), r);
	}
}
